/**
 * Created with IntelliJ IDEA.
 * User: Alex
 * Date: 12.06.13
 * Time: 21:01
 * To change this template use File | Settings | File Templates.
 */
class Position {
    int widthSpace;
    int lengthSpace;
    private int x_position;
    private int y_position;
    Position(int x_position, int y_position, int widthSpace, int lengthSpace) {
        this.x_position = x_position;
        this.y_position = y_position;
        this.widthSpace = widthSpace;
        this.lengthSpace = lengthSpace;
    }

    public int getPosition(String coordinates) {
        if (coordinates == "X") {
            return x_position;
        } else if(coordinates == "Y") {
            return y_position;
        } else return -1;
    }

    public boolean up(int steps) {
        if(steps > 0 && (x_position + steps) <= widthSpace) {

            x_position +=steps;
            return true;

        } else
            System.out.println("Illegal steps value");
            return false;
    }

    public boolean down(int steps) {

        if(steps > 0 && (x_position - steps) >= 0) {
            x_position -=steps;
            return true;
        } else
            System.out.println("Illegal steps value");
            return false;
    }

    public boolean left(int steps) {
        if(steps > 0 && (y_position - steps) >= 0) {
            y_position -=steps;
            return true;
        } else
            System.out.println("Illegal steps value");
            return false;
    }

    public boolean right(int steps) {
        if(steps > 0 && (y_position + steps) <= lengthSpace) {
            y_position +=steps;
            return true;
        } else
            System.out.println("Illegal steps value");
            return false;
    }
    //TODO works only if one steps
    public boolean upRight(int steps) {
        for (int stepUnusual = 0;stepUnusual < steps;stepUnusual++) {
            if ((x_position + steps) <= widthSpace && (y_position + steps) <= lengthSpace) {
                x_position += 1;
                y_position += 1;
                return true;
            } else return false;
        }
        return false;
    }
    //TODO works only if one steps
    public boolean downLeft(int steps) {
        for (int stepUnusual = 0;stepUnusual < steps;stepUnusual++) {
            if ((x_position - steps) >= 0 && (y_position - steps) >= 0) {
                x_position -= 1;
                y_position -= 1;
                return true;
            } else return false;
        }
        return false;

    }



}
